package com.leijingqi.controller;

import com.leijingqi.aop.myLog;
import com.leijingqi.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.util.UUID;

@Slf4j
@RestController
public class UploadController {

    @PostMapping("/upload")
    @myLog
    public Result upload(String username, Integer age, MultipartFile image)throws Exception {
        log.info("上传的数据:{},{},{}",username,age,image);
        //获取原始文件名
        String originalFilename = image.getOriginalFilename();
        //构建唯一的文件名
        int index = originalFilename.lastIndexOf(".");
        String uuid = UUID.randomUUID().toString();
        String fileName = originalFilename.substring(index);
        image.transferTo(new File("D:\\image\\"+uuid+fileName));
        return  Result.success();
    }
}
